package com.my.json.sensitive.config.handle;

import com.my.json.sensitive.config.AbstractSensitiveHandler;
import com.my.json.sensitive.enums.SensitiveType;
import org.apache.commons.lang3.StringUtils;

/**
 *@description 名字脱敏
 * @author hexinglin
 * @created 2021-12-29 15:30
 **/
public class ChineseNameSensitiveHandler  extends AbstractSensitiveHandler {
    public ChineseNameSensitiveHandler() {
    }

    @Override
    public SensitiveType strategy() {
        return SensitiveType.CHINESE_NAME;
    }
    @Override
    public String sensitive(String text) {
        if (StringUtils.isBlank(text)) {
            return "";
        } else {
            int length = StringUtils.length(text);
            String w = StringUtils.left(text, 1);
            if (length==2){
                return w.concat("*");
            }else if (length>2){
                String r = StringUtils.right(text, 1);
                return StringUtils.rightPad(w, length > 4 ? 4 : length, '*').concat(r);
            }
            return StringUtils.rightPad(w, length > 4 ? 4 : length, '*');
        }
    }

}

